﻿using Estsh.Core.Wms.IServices;
using Estsh.Core.Model.Result;
using Microsoft.AspNetCore.Mvc;
using Estsh.Core.Models;
using Estsh.Core.Controllers;

namespace Estsh.Core.Web.Plugin.Wms.Areas.wms.Controllers.InStock
{
    [Route("wms/[controller]")]
    [ApiController]
    public class OffLineProInStockController : WmsBaseController
    {
        private IOffLineProInStockService service;

        // GET: LoginController
        public OffLineProInStockController(IOffLineProInStockService _service)
        {
            service = _service;
        }

        /// <summary>
        /// 执行线外生产入库
        /// </summary>
        /// <param name="jobj"></param>
        /// <returns></returns>
        [HttpPost("CheckOffLineProInStock")]
        public IActionResult CheckOffLineProInStock(Newtonsoft.Json.Linq.JObject jobj)
        {
            string loginId = jobj["loginId"].ToString().Trim();
            string locateName = jobj["locateName"].ToString().Trim();
            string groupNo = jobj["groupNo"].ToString().Trim();
            string cartonNo = jobj["cartonNo"].ToString().Trim();

            WmsResponseResult result = new WmsResponseResult();
            try
            {
                string obj = service.CheckOffLineProInStock(loginId, cartonNo, locateName, groupNo);
                result.Success = true;
                result.Data = obj;
            }
            catch (Exception ex)
            {
                result.Msg = ex.Message;
            }
            return Json(result);
        }

        /// <summary>
        /// 生产入库订单列表
        /// </summary>
        /// <returns></returns>
        [HttpPost("ShowOffLineProInStockList")]
        public IActionResult ShowOffLineProInStockList()
        { 
            WmsResponseResult result = new WmsResponseResult();
            try
            {
                List<WmsInstock> obj = service.ShowOffLineProInStockList();
                result.Success = true;
                result.Data = obj;
            }
            catch (Exception ex)
            {
                result.Msg = ex.Message;
            }
            return Json(result);
        }

        /// <summary>
        /// 生产入库订单列表
        /// </summary>
        /// <returns></returns>
        [HttpPost("CheckWmsInstockStatus")]
        public IActionResult CheckWmsInstockStatus(Newtonsoft.Json.Linq.JObject jobj)
        {
            string loginId = jobj["loginId"].ToString().Trim();
            string orderNo = jobj["orderNo"].ToString().Trim();
            WmsResponseResult result = new WmsResponseResult();
            try
            {
                string obj = service.CheckWmsInstockStatus(loginId, orderNo);
                result.Success = true;
                result.Data = obj;
            }
            catch (Exception ex)
            {
                result.Msg = ex.Message;
            }
            return Json(result);
        }

        /// <summary>
        /// 生产入库订单列表
        /// </summary>
        /// <returns></returns>
        [HttpPost("GetInstock")]
        public IActionResult GetInstock(Newtonsoft.Json.Linq.JObject jobj)
        { 
            string orderNo = jobj["orderNo"].ToString().Trim();
            WmsResponseResult result = new WmsResponseResult();
            try
            {
                List<SysStock> obj = service.GetInstock(orderNo);
                result.Success = true;
                result.Data = obj;
            }
            catch (Exception ex)
            {
                result.Msg = ex.Message;
            }
            return Json(result);
        }
    }
}
